#assembler,linker
NASM := nasm
LINKER := ld

#nasm options 
ELF_FORMAT := -f elf

#sources and objects 
sources := $(wildcard *.asm) 
objects := $(patsubst %.asm,%.o,$(sources))

loader := Loader
loader_script := ../conf/loader.lds
loader_sources := $(wildcard ../boot/*.asm *.asm)
loader_objects := $(patsubst %.asm,%.o,$(loader_sources))

#ld options
LD_OPTIONS := -T $(loader_script)

#phony target
.PHONY:loader_all loader_clean

loader_all:$(objects) $(loader)

#assemble
SHELL := /bin/bash
$(objects):$(sources)
	for i in $(sources);do \
	$(NASM) $(ELF_FORMAT) $$i;\
	done

#loader
$(loader):$(loader_objects)
	$(LINKER) -o $(loader) $(LD_OPTIONS) $(loader_objects)

#phony target
loader_clean: 
	-rm $(objects) $(loader)
